import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mirac
 * Date: 2025-04-17
 * Time: 20:29
 */
public class main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        for(int i = 0; i <= a; i++){
            int count = 0;
            int temp = i;
            //计算i的位数
            while(temp != 0){
                count++;
                temp /= 10;
            }
            temp = i;
            int sum = 0;
            //判断是不是水仙花数
            while(temp != 0){
                sum += Math.pow(temp % 10,count);
                temp /= 10;
            }
            if(sum == i){
                System.out.println(i);
            }
        }
    }
}
